home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / language / instr.act < prev    next >
Text File  |  1995-04-22  |  1KB  |  60 lines

  1. ; INSTR.ACT 
  2. ; in-string? function for Action! 
  3.  
  4. ; By Bill Kendrick  New Breed Software 1994 
  5. ; (Originally written for Glenn Saunders <grin>) 
  6.  
  7. ; Accepts string to search in, string to look for, 
  8. ; starting point in string to start searching; 
  9. ; returns first location that string to look for is 
  10. ; found in the string to search in, or 0 if it cannot 
  11. ; be found. 
  12.  
  13. Byte Func InStr(Char Array String, Sub Byte Start) 
  14.   Byte Where,TempWhere,InSub,Look 
  15.  
  16.   Where=0       ; init for this call 
  17.   TempWhere=0 
  18.   InSub=1 
  19.    
  20.   If String(0)>=Start+Sub(0)-1 And String(0)>0 And Sub(0)>0 Then ; be sure enough room for it! 
  21.     For Look=Start To String(0) Do 
  22.       If String(Look)=Sub(InSub) Then 
  23.         If InSub=1 Then 
  24.           TempWhere=Look 
  25.         Fi ; this might be it 
  26.         InSub=InSub+1 
  27.         If InSub>Sub(0) Then 
  28.           Where=TempWhere ; it IS it! 
  29.           Look=String(0) ; easy way to POP a FOR loop :) 
  30.         Fi 
  31.       Else 
  32.         If TempWhere<>0 Then 
  33.           Look=TempWhere 
  34.         Fi 
  35.         InSub=1 ; no, that's not it! 
  36.         TempWhere=0 
  37.       Fi 
  38.     Od ; Look 
  39.   Fi 
  40. Return(Where) 
  41.  
  42. PROC TEST() 
  43.   CHAR ARRAY A(100),B(100) 
  44.   BYTE W 
  45.  
  46.   DO 
  47.     PRINTE("ENTER STRING") 
  48.     INPUTS(A) 
  49.     PRINTE("ENTER SEARCH") 
  50.     INPUTS(B) 
  51.     W=0 
  52.     DO 
  53.       W=INSTR(A,B,W+1) 
  54.       PRINTBE(W) 
  55.     UNTIL W=0 OD ; SEARCH UNTIL NO MORE 
  56.     PUTE() 
  57.   UNTIL B(0)=0 OD 
  58. RETURN 
  59.  
  60.